<?php
/*
 * Created on Mar 13, 2009
 *
 * author: David Palmer <blinder.dave@gmail.com>
 * This is an implementation of the Smarty template engine. 
 */

include_once("Smarty.class.php");
include_once(CLASSPATH."/org/dp/interfaces/TemplateEngine.php");
class SmartyEngine implements TemplateEngine {
	private $props;
	private $smarty;
	private $plugins;
	
	function __construct() {
		$this->smarty = new Smarty;
	}
	
	public function merge($template) {
		define(SMARTY_DIR,$this->props['smarty.dir']);

		$this->smarty->compile_dir=$this->props['smarty.templates_c'];
		$this->smarty->template_dir=$this->props['smarty.templates'];
		$this->smarty->config_dir=$this->props['smarty.config'];
		$this->smarty->cache_dir=$this->props['smarty.cache'];
		$this->smarty->caching=$this->props['smarty.caching'];
		if($this->plugins){
			foreach($this->plugins as $plugin){
				$plugin->execute($this,$template);
			}
		}
		return $this->smarty->fetch($template);
	}
	
	public function addObject($object) {
		$this->smarty->assign($object);
	}	
	
	public function setObject($key,$data) {
		$this->smarty->assign_by_ref($key,&$data);
	}
	
	public function setProps($props) {
		$this->props=$props;
	}
	
	public function getProps() {
		return $this->props;
	}
	
	public function setPlugins($plugins) {
		$this->plugins=$plugins;
	}
}
?>